/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
*
*
* Authors:                  zhoujian
* Email:            343600434@qq.com
* Date:         Sep-04-2024 18:22:39
*
*/


#include "speed_fifo.h"

static struct FIFO_CTRL  __speed_ctrl;


void speed_fifo_init(void)
{
    __speed_ctrl.tail = __speed_ctrl.head = 0;
}

void  speed_in(uint16_t sp_value)
{
    unsigned char tmp, i;
    tmp = __speed_ctrl.head;
    i = (tmp + 1) & _FIFO_MASK;

    if(i != __speed_ctrl.tail) {
        __speed_ctrl.head = i;
        __speed_ctrl.dat[tmp] = sp_value;
    }

    return;
}


unsigned char speed_out(uint16_t*   item)
{
    unsigned char tail = __speed_ctrl.tail;

    if(tail != __speed_ctrl.head) {
        *item = __speed_ctrl.dat[tail];
        __speed_ctrl.dat[tail] = 0;
        __speed_ctrl.tail = (tail + 1) & _FIFO_MASK;
        return 1;
    }

    return 0;
}


